"""设备管理模块，负责设备处理流程"""
from typing import List
from app_automation.app_factory import AppFactory
from core import ocr_processor
from utils import logger
import time

class DeviceProcessor:
    def __init__(self, ocr_processor: ocr_processor.OCRProcessor, app_name: str = "App1"):
        """
        初始化设备处理器
        
        :param ocr_processor: OCR处理器实例
        :param app_name: 要使用的应用名称
        """
        self.ocr_processor = ocr_processor
        # 使用AppFactory类创建应用实例
        self.app = AppFactory.create_app(app_name, ocr_processor)
        self.log = logger.get_logger("DeviceProcessor")
    
    def process_device(self, device_id: str):
        """处理单个设备的自动化流程"""
        self.log.info(f"处理设备: {device_id}")
        self.log.debug("-" * 40)
        
        try:
            # 执行应用自动化流程
            success = self.app.execute(device_id)
            status = "成功" if success else "失败"
            self.log.info(f"设备 {device_id} 处理{status}")
            return success
            
        except Exception as e:
            self.log.error(f"处理设备 {device_id} 时出错: {str(e)}")
            return False